package com.kristin.rmi.server;

import com.kristin.rmi.service.DemoService;
import com.kristin.rmi.service.serviceImpl.DemoServiceImpl;

import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

/**
 * @ClassName ServerMain
 * @Description TODO
 * @Author Kristin
 * @Date 2021/06/23 13:23:21
 * @Version 1.0.0
 */
public class ServerMain {


    public static void main(String[] args) throws RemoteException, AlreadyBoundException, MalformedURLException {

        // 1、启动rmi注册服务，指定端口号
        LocateRegistry.createRegistry(8888);

        // 2、创建要被访问的远程对象的实例
        DemoService demoService = new DemoServiceImpl();

        // 3、把远程对象实例注册到服务器上
        Naming.bind("rmi://localhost:8888/DemoService", demoService);

        System.out.println("服务端启动中");

    }

}
